#include <iostream>
#define N 100


//at ex 33 sum max should be 35  ??

using namespace std;

int maxvector(float sum[], int the_sum){
int i, max, pos;
max=sum[0];
for (i=1; i<the_sum; i++)
    if(sum[i]>max){
        max=sum[i];
        pos=i;
    }
return max;
}

int sum_elem_of_k(int array[], int elements, float sum[], int k){
int i, j, a, es=0; //es=element sum
    for (i=0;i<elements-k+1;i++){
        a=i;
        sum[es]=0;
        for (j=0;j<k;j++){
            sum[es] += array[a];
            ++a;
        }
        ++es;
    }
return es;
}

void readintVector(int array[], int elements){
for (int i=0; i<elements; i++){
	cout<<"a["<<i<<"]=";
	cin>>array[i];
	cout<<"\n";}
}

void printintVector(float sum[], int the_sum){
for(int i=0; i<the_sum; i++){
	cout<<sum[i]<<" ";}
	cout<<"\n";
}


int main(){
int k;
int the_sum;
float sum[N];
int array[N];
int elements;
int maxi;
cout<<"Type the number of elements you want in the array: ";
cin>>elements;

readintVector(array, elements);

cout<<"How many elements to sum at one time: ";
cin>>k;

cout<<"The original array is ";
for(int i=0; i<elements; i++){
	cout<<array[i]<<" ";}
cout<<endl;

the_sum=sum_elem_of_k(array, elements, sum, k);
cout<<"The sum of elements taken " << k <<" at a time are: ";
printintVector(sum, the_sum);

maxi=maxvector(sum, the_sum);
cout<<"Maxium sum is: "<< maxi<< endl;

return 0;
}
